package com.qf.smsplatform.controller.advice;

import com.qf.smsplatform.dto.R;
import com.qf.smsplatform.exception.MyBaseException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/*
统一处理程序中抛出的异常
 */
@ControllerAdvice//当前类是对controller进行aop增强的通知类
@ResponseBody//当前类中所有方法返回值都是R，都会通过相应正文返回
/*2021/10/25*/public class MyExceptionAdvice {

    /*

     */
    @ExceptionHandler(MyBaseException.class)//
    public R processMyBaseException(MyBaseException exception){
        int code=exception.getCode();
        String message = exception.getMessage();
        return R.setError(code, message, null);
    }
}
